package com.scau.database.controller.shopowner;

import com.scau.database.entity.shopowner.ShopOwnerQuery;
import com.scau.database.entity.shopowner.ShopOwnerVO;
import com.scau.database.service.shopowner.ShopOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: x1aolone
 * @Date: 2020/5/9 19:55
 */
@RestController
@RequestMapping("/api/shopowner")
public class ShopOwnerController {

    @Autowired
    public ShopOwnerService shopOwnerService;

    /**
     * 根据商品条形码从stock中获取有存货的仓库的id和剩余货量，并获取仓库的地址
     * @param barCode 条形码
     * @return 仓库id、该商品货量、地址
     */
    @GetMapping("/getStores/{barCode}")
    public List<ShopOwnerVO> getStores(@PathVariable String barCode) {
        return shopOwnerService.getStores(barCode);
    }

    /**
     * 根据商品名从中商品条形码，并从stock中获取货量
     * @param commodity 商品名
     * @return 条形码、商品名、库存
     */
    @GetMapping("/getStocks/{commodity}")
    public List<ShopOwnerVO> getStocks(@PathVariable String commodity) {
        return shopOwnerService.getStocks(commodity);
    }


    /**
     * 根据提交的数据，提交上架申请
     * @param query 商品条形码、上架数量、仓库id、商品原价、特价、是否特价、消费者三包期限、商店id
     * @return
     */
    @PostMapping("/commitShelfAddedApply")
    public Integer commitShelfAddedApply(@RequestBody ShopOwnerQuery query) {
        return shopOwnerService.commitShelfAddedApply(query);
    }

    /**
     * 通过商店id、商品名，搜索本店相关商品的商品名、价格、剩余数量、商品条形码
     * @param query 商店id、商品名
     * @return 相关商品的商品名、价格、剩余数量、商品条形码
     */
    @GetMapping("/searchGoodsByStoreIdAndCommodity")
    public List<ShopOwnerVO> searchGoodsByStoreIdAndCommodity(ShopOwnerQuery query) {
        return shopOwnerService.searchGoodsByStoreIdAndCommodity(query);
    }

    /**
     * 通过商店id、商品条形码，下架本店相关商品
     * @param query 商店id、商品条形码
     * @return
     */
    @PostMapping("/shelfDownGoods")
    public Integer shelfDownGoods(@RequestBody ShopOwnerQuery query) {
        return shopOwnerService.shelfDownGoods(query);
    }


}
